#ifndef laser_finder_H
#define laser_finder_H

#include <cv.h>
#include <highgui.h>
#include <vector>

class LaserFinder
{
private:
    int topLeftX;
    int topLeftY;
    int topRightX;
    int topRightY;
    int bottomLeftX;
    int bottomLeftY;
    int bottomRightX;
    int bottomRightY;
    int resultSizeX;
    int resultSizeY;
    int Hmin;
    int Hmax;
    int Smin;
    int Smax;
    int Vmin;
    int Vmax;

private:
    CvMat* warp_matrix;

    CvCapture* capture;
    int numOfImagesForFindAlike;

    int prevX;
    int prevY;
    int prevH;
    int prevS;
    int prevV;

    int counter;
    std::vector<CvPoint> track;

private:
    void drawTarget(IplImage* img, const int x, const int y, const int radius) const;
    void drawTrack(IplImage* img)const;
    void printText(IplImage* img, const int x, const int y, const char* text) const;
    void hsvFinder (const IplImage* image, IplImage* hsv_and) const;
    void brightFinder (const IplImage* img, int* x, int* y) const;
    void setTransformMatrix (const IplImage* frame);
    void perspectiveTransform (const IplImage* frame, IplImage* dst) const;
    bool findAlike(const IplImage* img, int* newx, int* newy) const;
    bool findLaser (IplImage* dst, int* minX, int* minY) const;
    void create();
    void setVideoStream (const char* videoStream, int cam_id);
    void loadParams (const char* configFile);
    void setCorners();
    void destroy();

public:
    LaserFinder(const char* videoStream, const char* configFile, int cam_id, int res_x, int res_y);
    ~LaserFinder();
    IplImage* getImage() const;
    bool getPoint(const IplImage* frame, int* x, int* y);
    int getEmptyCounter() const;
};

#endif

